package com.example.concurrentprogramming8016.thread;

import java.util.concurrent.TimeUnit;

/**
 * @author liyanhao
 * @Date 2023-01-03 1:23
 * 等待调用join方法的线程结束之后，程序再继续执行，一般用于等待异步线程执行完成结果之后才能继续运行的场景
 */
public class ThreadJoinDemo {
    public static void main(String[] args) throws InterruptedException {
        long l = System.currentTimeMillis();
        Thread thread = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("finished");
        });
        thread.start();
        thread.join();
        System.out.println((System.currentTimeMillis() - l));

    }
}
